﻿<?php

class TechnoDK_HttpRequest extends TechnoDK_Object
{
	private $_post;
	private $_get;
	private $_request;

	private static $_self;
	
	private function __construct()
	{
		$this->_post = $_POST;
		$this->_get = $_GET;
		$this->_request = $_REQUEST;
		unset($_POST, $_GET, $_REQUEST);
	}
	
	public static function getInstance()
	{
		if(!isset(self::$_self)){
			self::$_self = new self();
		}
		return self::$_self;
	}
	
	public function isAjax()
	{
		return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest');
	}
	
	public function getPost($name)
	{
		return isset($this->_post[$name]) ? $this->_post[$name] : false;
	}
	
	public function getQueryString()
	{
		return $_SERVER['QUERY_STRING'];
	}
	
	public function getQuery($name)
	{
		return isset($this->_get[$name]) ? $this->_get[$name] : false;
	}
	
	public function getBaseUrl()
	{
		return 'http://' . $_SERVER['HTTP_HOST'];
	}
	
	public function getCurrentUrl()
	{
		return $this->getBaseUrl() . $_SERVER['REQUEST_URI'];
	}
	
	public function isPost()
	{
		return ($_SERVER['REQUEST_METHOD'] == 'POST');
	}
	
	public function isGet()
	{
		return ($_SERVER['REQUEST_METHOD'] == 'GET');
	}
	
	public function getRequestMethod()
	{
		return $_SERVER['REQUEST_METHOD'];
	}
	
	public function getAllPost()
	{
		return $this->_post;
	}
	
	public function getAllQuery()
	{
		return $this->_get;
	}
	
	public function getAllParams()
	{
		return array(
			'POST' => $this->_post, 
			'GET' => $this->_get , 
			'REQUEST' => $this->_request
		);
	}

}



?>